package com.eight.msg;


import com.eight.msg.config.RabbitKeys;
import com.eight.msg.entity.RedUserHit;
import com.eight.msg.mapper.RedUserHitMapper;
import org.apache.commons.collections4.MapUtils;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.Map;
import java.util.logging.Logger;

@Component
@RabbitListener(queues = RabbitKeys.QUEUE_HIT)
public class PrizeHitReceiver {
    //private final static Logger logger = LoggerFactory.getLogger(PrizeHitReceiver.class);


    @Resource
    private RedUserHitMapper hitMapper;

    @RabbitHandler
    public void processMessage2(String message) {
        System.out.println("消费");
    }

    @RabbitHandler
    public void process1Message3(Map message) {
        RedUserHit hit = new RedUserHit();
        hit.setGameid(MapUtils.getIntValue(message,"gameid"));
        hit.setUserid(MapUtils.getIntValue(message,"userid"));
        hit.setProductid(MapUtils.getIntValue(message,"productid"));
        hit.setHittime(new Date(MapUtils.getLongValue(message,"hittime")));
        hitMapper.insert(hit);
    }

    @RabbitHandler
    public void processMessage2(RedUserHit message) {
        hitMapper.insert(message);
    }
}